import 'package:flutter/material.dart';
import 'package:tencent_cloud_chat_sdk/models/v2_tim_group_member_full_info.dart';
import 'package:tencent_cloud_chat_sdk/models/v2_tim_message.dart';
import 'package:video_ducafecat_flutter_v3/common/index.dart';

/// 本机自定义消息
class MsgCustomElemWidget extends StatelessWidget {
  const MsgCustomElemWidget(
      {super.key, this.membersList, required this.message});

  final List<V2TimGroupMemberFullInfo?>? membersList;
  final V2TimMessage message;

  // 消息提示
  Widget _buildTip(String tip) {
    return TextWidget.body1(
      tip,
      color: AppColors.secondary.withOpacity(0.5),
      softWrap: true,
      maxLines: null,
      textAlign: TextAlign.center,
    ).paddingVertical(AppSpace.listRow).center();
  }

  // 主视图
  Widget _buildView() {
    String? members = membersList?.map((e) => e?.nickName ?? "").join(", ");
    return _buildTip(IMService.to.groupLocalMessageText(
      message.customElem?.data ?? "",
      members: members,
    ));
  }

  @override
  Widget build(BuildContext context) {
    return _buildView();
  }
}
